<!DOCTYPE html>
<html lang="">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta itemprop="name" content="Docker安装">
<meta itemprop="description" content="docker 安装 # 安装软件包yum install -y yum-utils \ device-mapper-persistent-data \ lvm2# 设置仓库源# 否则安装比较缓慢sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# 安装社区版# -y 中间自动同意，不需要人工干预yum install -y docker-ce docker-ce-cli containerd.io# 启动dockersystemctl start docker# 设置开机启动systemctl enable docker设置docker数据存储位置  因为系统盘一般比较小，如果有额外的数据盘，建议将将docker数据放到数据盘
 # 修改docker默认存储位置# 停止docker服务systemctl stop docker.socketsystemctl stop docker.service# 移动数据到新的目录mv /var/lib/docker /data/docker# 修改docker.service文件，使用-graph参数指定存储位置# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.">
<meta itemprop="datePublished" content="2024-02-21T10:55:53&#43;08:00" />
<meta itemprop="dateModified" content="2024-02-21T10:55:53&#43;08:00" />
<meta itemprop="wordCount" content="115">



<meta itemprop="keywords" content="" /><meta property="og:title" content="Docker安装" />
<meta property="og:description" content="docker 安装 # 安装软件包yum install -y yum-utils \ device-mapper-persistent-data \ lvm2# 设置仓库源# 否则安装比较缓慢sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# 安装社区版# -y 中间自动同意，不需要人工干预yum install -y docker-ce docker-ce-cli containerd.io# 启动dockersystemctl start docker# 设置开机启动systemctl enable docker设置docker数据存储位置  因为系统盘一般比较小，如果有额外的数据盘，建议将将docker数据放到数据盘
 # 修改docker默认存储位置# 停止docker服务systemctl stop docker.socketsystemctl stop docker.service# 移动数据到新的目录mv /var/lib/docker /data/docker# 修改docker.service文件，使用-graph参数指定存储位置# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd." />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.lican.site/postsbak/docker%E5%AE%89%E8%A3%85/" />
<meta property="article:published_time" content="2024-02-21T10:55:53+08:00" />
<meta property="article:modified_time" content="2024-02-21T10:55:53+08:00" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Docker安装"/>
<meta name="twitter:description" content="docker 安装 # 安装软件包yum install -y yum-utils \ device-mapper-persistent-data \ lvm2# 设置仓库源# 否则安装比较缓慢sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# 安装社区版# -y 中间自动同意，不需要人工干预yum install -y docker-ce docker-ce-cli containerd.io# 启动dockersystemctl start docker# 设置开机启动systemctl enable docker设置docker数据存储位置  因为系统盘一般比较小，如果有额外的数据盘，建议将将docker数据放到数据盘
 # 修改docker默认存储位置# 停止docker服务systemctl stop docker.socketsystemctl stop docker.service# 移动数据到新的目录mv /var/lib/docker /data/docker# 修改docker.service文件，使用-graph参数指定存储位置# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd."/>

	<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
	<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
	<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
	<link rel="manifest" href="/site.webmanifest">
	<link rel="mask-icon" href="/safari-pinned-tab.svg" color="">
	<link rel="shortcut icon" href="/favicon.ico">

	<title>Docker安装</title>
	<link rel="stylesheet" href="https://www.lican.site/css/style.min.d3141168199607bf3a517216ce3c263814eecdbc8fca72a9a88700799a838219.css">
	
</head>

<body id="page">
	
	<header id="site-header" class="animated slideInUp faster">
		<div class="hdr-wrapper section-inner">
			<div class="hdr-left">
				<div class="site-branding">
					<a href="https://www.lican.site">花落雨忧</a>
				</div>
				<nav class="site-nav hide-in-mobile">
					<a href="https://www.lican.site/posts">首页</a>
					<a href="https://www.lican.site/tech/">技术文档</a>
					<a href="https://www.lican.site/article/">文章</a>
					<a href="https://www.lican.site/project/">项目</a>
					<a href="https://www.lican.site/about/">关于</a>
				</nav>
			</div>
			<div class="hdr-right hdr-icons">
				<button id="menu-btn" class="hdr-btn" title="Menu"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></button>
			</div>
		</div>
	</header>
	<div id="mobile-menu" class="animated fast">
		<ul>
			<li><a href="https://www.lican.site/posts">首页</a></li>
			<li><a href="https://www.lican.site/tech/">技术文档</a></li>
			<li><a href="https://www.lican.site/article/">文章</a></li>
			<li><a href="https://www.lican.site/project/">项目</a></li>
			<li><a href="https://www.lican.site/about/">关于</a></li>
		</ul>
	</div>


	<main class="site-main section-inner thin animated fadeIn faster">
		<h1>Docker安装</h1>
		<div class="content">
			<h3 id="docker-安装">docker 安装<a href="#docker-安装" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg></a></h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 安装软件包</span>
yum install -y yum-utils <span style="color:#ae81ff">\</span>
  device-mapper-persistent-data <span style="color:#ae81ff">\</span>
  lvm2
<span style="color:#75715e"># 设置仓库源</span>
<span style="color:#75715e"># 否则安装比较缓慢</span>
sudo yum-config-manager <span style="color:#ae81ff">\</span>
    --add-repo <span style="color:#ae81ff">\</span>
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

<span style="color:#75715e"># 安装社区版</span>
<span style="color:#75715e"># -y  中间自动同意，不需要人工干预</span>
yum install -y docker-ce docker-ce-cli containerd.io

<span style="color:#75715e"># 启动docker</span>
systemctl start docker

<span style="color:#75715e"># 设置开机启动</span>
systemctl enable docker

</code></pre></div><h3 id="设置docker数据存储位置">设置docker数据存储位置<a href="#设置docker数据存储位置" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg></a></h3>
<blockquote>
<p>因为系统盘一般比较小，如果有额外的数据盘，建议将将docker数据放到数据盘</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 修改docker默认存储位置</span>
<span style="color:#75715e"># 停止docker服务</span>
systemctl stop docker.socket
systemctl stop docker.service
<span style="color:#75715e"># 移动数据到新的目录</span>
mv /var/lib/docker /data/docker
<span style="color:#75715e"># 修改docker.service文件，使用-graph参数指定存储位置</span>
<span style="color:#75715e"># ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /data/docker</span>
vim /usr/lib/systemd/system/docker.service
<span style="color:#75715e"># reload并重启docker</span>
systemctl daemon-reload
systemctl restart docker.service
<span style="color:#75715e"># 确认docker信息</span>
docker info
</code></pre></div><h3 id="docker-compose-安装">docker-compose 安装<a href="#docker-compose-安装" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg></a></h3>
<blockquote>
<p>因为应用程序有启动顺序要求，所以需要通过docker-compose进行服务编排</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">下载docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span>
<span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">也可使用下载好的</span>(<span style="color:#a6e22e">当前目录下的docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">cmpose</span><span style="color:#f92672">-</span><span style="color:#ae81ff">1.29.2</span>)
<span style="color:#a6e22e">sudo</span> <span style="color:#a6e22e">curl</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">L</span> <span style="color:#e6db74">&#34;https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)&#34;</span> <span style="color:#960050;background-color:#1e0010">\</span>
<span style="color:#f92672">-</span><span style="color:#a6e22e">o</span> <span style="color:#f92672">/</span><span style="color:#a6e22e">usr</span><span style="color:#f92672">/</span><span style="color:#a6e22e">local</span><span style="color:#f92672">/</span><span style="color:#a6e22e">bin</span><span style="color:#f92672">/</span><span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span>

<span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">赋予可执行权限</span>
<span style="color:#a6e22e">chmod</span> <span style="color:#f92672">+</span><span style="color:#a6e22e">x</span> <span style="color:#f92672">/</span><span style="color:#a6e22e">usr</span><span style="color:#f92672">/</span><span style="color:#a6e22e">local</span><span style="color:#f92672">/</span><span style="color:#a6e22e">bin</span><span style="color:#f92672">/</span><span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span>

<span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">创建软连接</span>(<span style="color:#a6e22e">加入环境</span>)
<span style="color:#a6e22e">ln</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">s</span> <span style="color:#f92672">/</span><span style="color:#a6e22e">usr</span><span style="color:#f92672">/</span><span style="color:#a6e22e">local</span><span style="color:#f92672">/</span><span style="color:#a6e22e">bin</span><span style="color:#f92672">/</span><span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span> <span style="color:#f92672">/</span><span style="color:#a6e22e">usr</span><span style="color:#f92672">/</span><span style="color:#a6e22e">bin</span><span style="color:#f92672">/</span><span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span>

<span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">测试是否安装成功</span>
<span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span> <span style="color:#f92672">--</span><span style="color:#a6e22e">version</span>
</code></pre></div><blockquote>
<p>备注：网络原因，可能下载失败，也可以使用 ./docker下的docker-comopse-1.29.2版本</p>
</blockquote>

		</div>
	</main>

	<footer id="site-footer" class="section-inner thin animated fadeIn faster">
		<p>&copy; 2024 <a href="https://www.lican.site"></a></p>
		<p>
			Made with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a> &#183; Theme <a href="https://github.com/Track3/hermit" target="_blank" rel="noopener">Hermit</a> &#183; <a href="https://www.lican.site/post/index.xml" target="_blank" title="rss"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-rss"><path d="M4 11a9 9 0 0 1 9 9"></path><path d="M4 4a16 16 0 0 1 16 16"></path><circle cx="5" cy="19" r="1"></circle></svg></a>
		</p>
	</footer>


	<script src="https://www.lican.site/js/main.min.784417f5847151f848c339cf0acb13a06cbb648b1483435a28ed4556c4ead69b.js"></script>

</body>

</html>
